package com.lightsh.handwritten;

import java.util.ArrayList;

import com.lightsh.db.MyDbHelper;
import com.lightsh.viewpager.BaseFragment;
import com.lightsh.viewpager.MyPagerAdapter;
import com.lightsh.viewpager.NoteListFragment;
import com.lightsh.viewpager.PaintListFragment;
import com.viewpagerindicator.TitlePageIndicator;
import com.viewpagerindicator.TitlePageIndicator.IndicatorStyle;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.util.Log;

public class MainActivity extends FragmentActivity{

	private ViewPager mPager;
	private TitlePageIndicator mIndicator;
	private MyPagerAdapter mAdapter;
	
	private ArrayList<BaseFragment> mFragments;
	private ArrayList<String> mTitles;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		mPager = (ViewPager) findViewById(R.id.pager);
		mIndicator = (TitlePageIndicator) findViewById(R.id.indicator);
		
		mFragments = new ArrayList<BaseFragment>();
		mTitles = new ArrayList<String>();
		
		mFragments.add(new NoteListFragment());
		mTitles.add(getString(R.string.note));
		
		mFragments.add(new PaintListFragment());
		mTitles.add(getString(R.string.paint));
		
		mAdapter = new MyPagerAdapter(getSupportFragmentManager(), mFragments, mTitles);
		mPager.setAdapter(mAdapter);
		
		mIndicator.setViewPager(mPager);
		mIndicator.setFooterIndicatorStyle(IndicatorStyle.Underline);
		mIndicator.setTextColor(getResources().getColor(R.color.black));
		mIndicator.setSelectedColor(getResources().getColor(R.color.blue));
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	@Override
	public void onBackPressed() {
		int index = mPager.getCurrentItem();
		if(index < mFragments.size()){
			BaseFragment bf = mFragments.get(mPager.getCurrentItem());
			if(bf.onBackPressed()){
				return;
			}
		}
		super.onBackPressed();
	}
	
}
